package net.sparrow.module;

import net.minecraft.src.Minecraft;
import net.sparrow.Sparrow;
import net.sparrow.cmd.CommandHandler;
import net.sparrow.event.DataField;
import net.sparrow.event.SpEventListener;
import net.sparrow.event.SpKeyboardEvent;
import net.sparrow.gui.screens.SpConsole;
import net.sparrow.gui.screens.SpMiniConsole;
import net.sparrow.util.Util;

public class ConsoleModule extends Module {

	
	@DataField( id = "gui.console")
	public Boolean isOpen = false;
	
	@DataField( id = "gui.bigconsole")
	public Boolean bigConsole = false;
	
	private SpMiniConsole miniConsole = new SpMiniConsole();
	private SpConsole console = new SpConsole();
	
	public void onCommandToggle() {
		if (Sparrow.mc().currentScreen() instanceof SpMiniConsole) {
			Sparrow.mc().displayScreen(null);
			isOpen = false;
		} else {
			Sparrow.mc().displayScreen(bigConsole?console:miniConsole);
			isOpen = true;
		}
	}
	
	public CommandHandler loadCommands() {
		return new CommandHandler().withDefaultToggle("gui.bigconsole");
	}
	
	public boolean onCommand(String[] args) {
		if (args[1].equals("toggle")) {
			
			if (args[0].equals("gui.console")) {
				onCommandToggle();
			}
			return true;
		}
		
		return false;
	}
	
	public void addMsg(String msg) {
		Util.print("[CMDS] " + msg);
		if (Sparrow.mc().currentScreen() == console) {
			console.addConsoleMsg(msg);
		}
		if (Sparrow.mc().currentScreen() == miniConsole) {
			console.addConsoleMsg(msg);
		}
	}
	
	
	@SpEventListener
	public void onKey(SpKeyboardEvent event) {
		if (event.character == '0' && Sparrow.mc().currentScreen() == null) { //hardcoded console toggle event
			onCommandToggle();
		}
	}
}
